<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Inicio extends CI_Controller {

    function __construct(){
        parent::__construct();
        $this->lang->load('lang/ini_'.$this->config->item('language'), $this->config->item('language'));
        $this->template->write_view('footer', 'footer');
        $this->template->write_view('header', 'header');
        //$this->template->write_view('_scripts', 'js', array('ruta' => site_url().'public/'.$this->template->getActiveTemplate(),
        //                                                    'lugares' => $this->lugares()));
        $this->template->write_view('_scripts', 'js', array('ruta' => site_url().'public/'.$this->template->getActiveTemplate()));
        $this->template->write_view('_styles', 'css', array('ruta' => site_url().'public/'.$this->template->getActiveTemplate()));
    }

    public function index(){
        $this->load->helper('form');
        $this->load->model('producto_model');
        $this->load->model('promocion_model');
        $this->load->model('blog_model');
        $this->load->library('Controlador');
        $data['posts'] = $this->blog_model->get_posts(5, 0);
        $data['comments'] = $this->blog_model->get_lasts_comment(5, 0);
        $data['lugares'] = form_dropdown('p_lugares', $this->lugares(), '', 'id="p_lugares" style="display:none;" multiple="multiple"');
        $data['productos'] = $this->producto_model->buscar_portada(5);
        $data['ruta_template'] = $this->template->getActiveTemplate();
        $data['datos_tags'] = $this->producto_model->getUltimasProvinciasConReserva();
        $data['datos_slider'] = $this->promocion_model->getPromociones(null, null, 5, 'S');
        $this->template->write_view('content', 'content/inicio', $data);
        $this->template->render();
    }

    function login(){
        $this->load->library('loginlib');
        if($this->loginlib->login($this->input->post('usu_email'), $this->input->post('usu_password'))) {
            redirect();
        } else {
            $this->session->set_flashdata('error_usuario', lang('usuario_incorrecto'));
            redirect();
        }
    }

    function logout(){
        $this->load->library('loginlib');
        $this->loginlib->logout();
        redirect();
    }
    
    function lugares(){
        $this->load->model('inicio_model');
        return $this->inicio_model->getLugares();
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */